export default {
	namespaced:true,
	state: {
		CartList:[],
	},
	getters: {
		getCartLen: state=>{
			return state.CartList.filter(item => item.show == false).length;
		},
		getCarList: state=>{
			return state.CartList.filter(item => item.show == false);
		}
	},
	mutations: {
		add(state,obj){
		   let index = null;   
		   index = state.CartList.findIndex(item => item.goodId == obj.goodId && item.type == obj.type && item.show == false);
			console.log(index);
			if(index != -1){
				state.CartList[index].count+=obj.count;
				return;
			}
			state.CartList.push(obj);
		},
		UpdateCart(state,obj){
			let index = state.CartList.findIndex(item => item.id == obj.id);
			state.CartList[index] = obj;
		}
		
		
	},
	actions: {
		addCart(context,obj){
			context.commit('add',obj)
		},
		UpCart(context,obj){
			context.commit('UpdateCart',obj);
		}
	}
}